package com.leyou.item.client;

import com.leyou.common.dto.PageDTO;
import com.leyou.item.dto.*;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@FeignClient("item-service")
public interface ItemClient {

    /**
     * 关于商品spu的分页查询
     *
     * @param page
     * @param rows
     * @param cId
     * @param bid
     * @param saleable
     * @param id
     * @return
     */
    @GetMapping("goods/spu/page")
    PageDTO<SpuDTO> pageQuery(
            @RequestParam(value = "page", defaultValue = "1") Integer page,
            @RequestParam(value = "rows", defaultValue = "5") Integer rows,
            @RequestParam(value = "categoryId", required = false) Long cId,
            @RequestParam(value = "brandId", required = false) Long bid,
            @RequestParam(value = "saleable", required = false) Boolean saleable,
            @RequestParam(value = "id", required = false) Long id);


    /**
     * 根据spuId查询对应的sku的集合
     *
     * @param spuId
     * @return
     */
    @GetMapping("goods/sku/of/spu")
    List<SkuDTO> querySkuBySpuId(@RequestParam("id") Long spuId);


    /**
     * 根据spuId查询spu的所有规格参数值
     *
     * @param id spu的id
     * @return 规格参数值
     */
    @GetMapping("goods/spec/value")
    List<SpecParamDTO> querySpecsValues(
            @RequestParam("id") Long id,
            @RequestParam(value = "searching", required = false) Boolean searching);


    /**
     * 根据品牌的id集合，查询对应的品牌集合，List<Entity>=====》List<DTO>
     *
     * @param ids
     * @return
     */
    @GetMapping("/brand/list")
    List<BrandDTO> queryBrandByIds(@RequestParam("ids") List<Long> ids);

    /**
     * 根据分类的id集合查询分类的集合
     *
     * @param ids
     * @return
     */
    @GetMapping("/category/list")
    List<CategoryDTO> queryCategoryByIds(@RequestParam("ids") List<Long> ids);


    /**
     * 根据spuId查询对应的spu及spuDetail，sku信息
     *
     * @param spuId
     * @return
     */
    @GetMapping("/goods/{id}")
    SpuDTO querySpuById(@PathVariable("id") Long spuId);


    /**
     * 根据spuId查询对应的spuDetail信息
     *
     * @param spuId
     * @return
     */
    @GetMapping("/goods/spu/detail")
    SpuDetailDTO querySpuDetailById(@RequestParam("id") Long spuId);


    /**
     * 根据品牌id查询对应的品牌对象
     *
     * @param brandId
     * @return
     */
    @GetMapping("/brand/{id}")
    BrandDTO queryBrandById(@PathVariable("id") Long brandId);


    /**
     * 根据分类id查询对应的规格参数组以及组内参数
     *
     * @param cid
     * @return
     */
    @GetMapping("/spec/list")
    List<SpecGroupDTO> querySpecList(@RequestParam("id") Long cid);

    /**
     * 根据sku的id集合查询对应的sku集合
     *
     * @param ids
     * @return
     */
    @GetMapping("/goods/sku/list")
    List<SkuDTO> querySkuByIds(@RequestParam("ids") List<Long> ids);

    /**
     * 批量扣减库存，map的key为skuId，value为对应数量
     *
     * @param minusMap
     * @return
     */
    @PutMapping("/goods/stock/minus")
    Void deductStock(@RequestBody Map<Long, Integer> minusMap);

    /**
     * 批量加库存，map的key为skuId，value为对应数量
     * @param plusMap
     * @return
     */
    @PutMapping("/goods/stock/plus")
     Void addStock(@RequestBody Map<Long,Integer> plusMap);
}
